import random

setGlobalDuration(30.4)

env = genAdsr(release=0.8)

# tableMorphing index variation
line = genLineseg([0, 150, 0, 200, 0.5, 150, 0.5, 200, 1, 150, 1, 0, 0, 150, 0, 200, 0.5, 150, 0.5, 200, 1, 150, 1])
readTable(bus='ind', table=line, duration=30)

# rythm tables to morph between
tt1 = genDataTable([1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0])
tt2 = genDataTable([0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0])
tt3 = genDataTable([1,0,1,0,1,1,1,0,1,0,0,0,1,0,1,1])
tapTable = tableMorphing(tablelist=[tt1, tt2, tt3], indexVar='ind', length=16)

# pitch tables to morph between
pi1 = genDataTable([1,1,1,1,.5,1,1,1,.25,1,1,1,.125,1,1,1])
pi2 = genDataTable([.5,1,.5,1,.5,1,.5,1,.25,1,.5,1,.25,1,.5,1])
pi3 = genDataTable([.5,.5,.25,.5,.5,.5,.25,.5,.25,.5,.5,.5,.25,.5,.5,.25])
pitTable = tableMorphing(tablelist=[pi1, pi2, pi3], indexVar='ind', length=16)

metro(bus='metro', tempo=132)

# bass sequence
beginSequencer(input='metro', table=tt1)
notes = 10
pitchs = [random.randint(180,190)*0.125 for x in range(notes)]
durs = [random.randint(1,10)*.08 for x in range(notes)]
readTable(bus='index', table=env, duration=durs[0])
freqMod(pitch=pitchs, amplitude=.07, starttime=0, duration=durs, envelope=env, pan=[0,.25,.5,.75,1], index=30, indexVar='index')
endSequencer()

# solo sequence
beginSequencer(input='metro', table=tapTable)
sequencerPitchTable(pitTable)
notes = 10
pitchs = [random.randint(180,190)*2 for x in range(notes)]
durs = [random.randint(1,15)*.05 for x in range(notes)]
readTable(bus='index2', table=env, duration=durs[0])
freqMod(pitch=pitchs, modulator=0.502, amplitude=.07, starttime=0, duration=durs, envelope=env, pan=[0,.25,.5,.75,1], index=10, indexVar='index2')
endSequencer()

startCsound()

